#pragma once

#include<iostream>
#include<vector>
#include<string>
#include<errno.h>
#include<cstring>
#include<cassert>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>

#define PROCESSNUM 3
#define NAME_PIPE "/tmp/mypipe" //想在共享目录下创建命名管道
#define MAKE_SRAND() srand((unsigned int)time(0))

typedef void (*func_t)();

class processEp
{
public:
    processEp(std::string& namePipe,int writeFd)
    :_namePipe(namePipe),_writeFd(writeFd)
    {}

public:
    std::string _namePipe;    // 管道文件的文件名
    int _writeFd;             // 写端的文件描述符
};

extern std::vector<processEp> pros; 
extern std::vector<func_t> funcMap; 

bool creatFifo(const std::string& path)
{
    umask(0);
    int n = mkfifo(path.c_str(),0666);
    if(n == 0) return true;
    else{
        std::cout << "errno:" << errno << " err string:" << strerror(errno) << std::endl;
        return false;
    }
}

void removeFifo(const std::string& path)
{
    int n = unlink(path.c_str());
    assert(n == 0); // debug , release 里面就没有了
    (void)n;
}

